{% extends "base_master.html" %}



{% block include %}
<link rel="stylesheet" href="/resources/css/sheet.css" type="text/css" />
<script type="text/javascript" src="/resources/3th/jquery-jquery-ui-269fcfb/ui/jquery.ui.autocomplete.js"></script>
{% endblock %}



{% block script %}
$(function(){


	$("#complete").autocomplete({
		source:function(req, add){
			$.getJSON("/code/select/", req, function(data){
				
				add($.map(data, function(item){
					return{
						label:"(" + item.code + ")" + item.label,
						code:item.code
					};
				}));
				
			});
		},
		focus:function(e, ui){
		},
		//define select handler
		select: function(e, ui) {
			
			$("#label").children().remove();
			$("#label").html( ui.item.label);
			
			$("input[name='foo']").val(ui.item.code);
			
			
			//$("#label").val(ui.item.label);
			//$("#value").val(ui.item.code);
			
			//create formatted friend
			/*var friend = ui.item.value,
				span = $("<span>").text(friend),
				a = $("<a>").addClass("remove").attr({
					href: "javascript:",
					title: "Remove " + friend
				}).text("x").appendTo(span);

				//add friend to friend div
				span.insertBefore("#to");*/
			},

			//define select handler
			change: function() {


				//prevent 'to' field being updated and correct position
				//$("#to").val("").css("top", 2);
			}
	});


});
{% endblock %}

{%block body %}
<div>
	<h3>Code Details</h3>
</div>


<form action="/code/create" method="post">
	<div>
		<fieldset>
			<legend>기본정보</legend>
			
			<ul class="inputFieldList">
				{{form.non_field_errors}}
				
				
				<div class="fieldWrapper">
					<li>{{form.house_code.errors}} {{form.house_code.label}}</li>
					<li>
						{{form.house_code}}
					</li>
				</div>
				
				
				<div class="fieldWrapper">
					<li>
						{{form.code.errors}}
						<label for="id_code" >{{form.code.label}}</label>
					</li>
					<li>
						{{form.code}}
					</li>
				</div>
				
				
				<div class="fieldWrapper">
					<li>{{form.description.errors}} {{form.description.label}}</li>
					<li>
						{{form.description}}
					</li>
				</div>
				
				
				<div class="fieldWrapper">
					<li>{{form.used.errors}} {{form.used.label}}</li>
					<li>
						{{form.used}}
					</li>
				</div>
				<div class="fieldWrapper">
					<li>{{form.sort_seq.errors}} {{form.sort_seq.label}}</li>
					<li>
						{{form.sort_seq}}
					</li>
				</div>
				
				<div class="fieldWrapper">
					<li>{{form.memo.errors}} {{form.memo.label}}</li>
					<li>
						{{form.memo}}
					</li>
				</div>
				
				
			</ul>
		</fieldset>
		<fieldset>
			<legend>관련코드정보</legend>
			<ul>
				
				<li>상위코드</li>
				<li>{{form.super_code}}
				</li>
				<li>
					<input type="text"id="complete" />
					<div id="label" ></div>
					{{form.foo}}
				</li>
				
			</ul>
		</fieldset>
		<button >저장</button>
	</div>
</form>	
{% endblock %}
